package com.cctc.controller;

import jakarta.servlet.http.Part;
import org.springframework.stereotype.Controller;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Optional;

/**
 * @Name FileUploadController
 * @Description: 文件上传控制器
 * @Author: lichao
 * @Email: li2chao@126.com
 * @Date: 2024-01-24 17:01:30
 **/
@Controller
public class FileUploadController {

    /**
     * 表单提交: 单文件上传
     * @param filename 文件名称
     * @param content 文件内容
     * @return java.lang.String
     * @author lichao
     * @email li2chao@126.com
     * @date 2024/01/24 17:23:32
     */
    @PostMapping("/form/upload")
    public String upload(@RequestParam("filename") String filename,
                         @RequestParam("content") MultipartFile content) {
        boolean flag = true;
        // 上传文件处理...
        if (flag) {
            return "redirect:uploadSuccess";
        }
        return "redirect:uploadFailure";
    }

    /**
     * 表单提交：多文件上传
     * @param files 文件集合
     * @return java.lang.String
     * @author lichao
     * @email li2chao@126.com
     * @date 2024/01/24 17:25:04
     */
    @PostMapping("/form/batchupload")
    public String batchUpload(@RequestParam MultiValueMap<String, MultipartFile> files) {
        boolean flag = true;
        // 批量上传文件处理...
        if (flag) {
            return "redirect:uploadSuccess";
        }
        return "redirect:uploadFailure";
    }

    @PostMapping("/curl/upload")
    public String handle(@RequestPart("file-data") MultipartFile file) {
        boolean flag = true;
        // 上传文件处理...
        if (flag) {
            return "redirect:uploadSuccess";
        }
        return "redirect:uploadFailure";
    }




}

